#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

bool compare(vector<int> a,vector<int> b){
    
    if(a[1]==b[1]){
        return a[0]>b[0];
    }
    return a[1]<b[1];
}

class Solution {
public:
    int eraseOverlapIntervals(vector<vector<int>>& intervals) {
        int result = 0;
        sort(intervals.begin(),intervals.end(),compare);
        vector<vector<int>> inter;
        for(int i = 0 ;i<intervals.size();++i){
            if(inter.size()==0){
                inter.push_back(intervals[i]);
            }
            else{
                if(intervals[i][0]<inter.back()[1]){
                    ++result;
                }
                else{
                    inter.push_back(intervals[i]);
                }
            }
        }
        return result;

    }
};

void func(){
    int v1 = 2;
    auto f = [v1] () mutable {return ++v1;};
}

int main(){
    Solution S;
    vector<vector<int>> V = {{1,2},{1,2},{1,2}};
    cout<<S.eraseOverlapIntervals(V)<<endl;
    
}